/**
 * 
 */
package com.sx.article.action;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ModelDriven;
import com.sx.article.biz.ITitleInfoBiz;
import com.sx.article.entity.TitleEntity;
import com.sx.core.BaseAction;
import com.sx.feesunit.exception.SXException;
import com.sx.util.date.DateUtil;

/**
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class TitleInfoAction extends BaseAction implements ModelDriven<TitleEntity> {
	private ITitleInfoBiz titleinfobiz;
	private TitleEntity title = new TitleEntity();
	private Log log = LogFactory.getLog(this.getClass());
	/**
	 * 新增标题信息
	 **/
	public void addTitleInfo() throws SXException{
		try {
			String today = DateUtil.getToday();
			title.setTdatetime(today);
			Integer id = titleinfobiz.addTitleInfo(title);
			if (id!=null) {
				outJsonString("{success:true,tid:"+id+"}");
			} else {
				outJsonString("{success:false}");
			}
			
		} catch (Exception e) {
			outJsonString("{success:false}");
			log.error("新增标题信息",e);
			throw new SXException();
			// TODO: handle exception
		}
	}
	/**
	 * 修改标题信息
	 **/
	public void updateTitleInfo(){
		try {
			String today = DateUtil.getToday();
			title.setTdatetime(today);
			boolean flag = titleinfobiz.updateTitleInfo(title);
			if (flag) {
				outJsonString("{success:true}");
			} else {
				outJsonString("{success:false}");
			}
		} catch (Exception e) {
			outJsonString("{success:false}");
			log.error("修改标题信息",e);
			
			// TODO: handle exception
		}
	}
	/**
	 * 删除标题信息
	 **/
	public void deleteTitleInfo(){
		try {
			boolean flag = titleinfobiz.deleteTitleInfo(title);
			if (flag) {
				outJsonString("{success:true}");
			} else {
				outJsonString("{success:false}");
			}
		} catch (Exception e) {
			outJsonString("{success:false}");
			log.error("删除标题信息",e);
			
			// TODO: handle exception
		}
	}
	/**
	 * 获取所有标题信息
	 **/
	public void findTitleEntityInfo(){
		String str = "{data:[],totalCount:0}";
		try {
			str = titleinfobiz.findTitleEntityJSONInfo(title);
		} catch (Exception e) {
			log.error("获取所有标题信息",e);
			
			// TODO: handle exception
		}
		outJsonString(str);
	}
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
	 */
	public TitleEntity getModel() {
		// TODO Auto-generated method stub
		return title;
	}
	/**
	 * @return the titleinfobiz
	 */
	public ITitleInfoBiz getTitleinfobiz() {
		return titleinfobiz;
	}
	/**
	 * @param titleinfobiz the titleinfobiz to set
	 */
	public void setTitleinfobiz(ITitleInfoBiz titleinfobiz) {
		this.titleinfobiz = titleinfobiz;
	}
	
}
